package com.ch.produce.core.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author cj-ch
 * @date 2018/4/21 下午2:46
 */
@RestController
public class HystrixTestController {
    final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ServiceInstance serviceInstance;


    @RequestMapping("/hystrix-test")
    public String hystrixTest(){
        logger.info("/hello,host:{},service_id:{}",serviceInstance.getHost(),serviceInstance.getServiceId());
        int i = new Random().nextInt(3000);
        try {
            //测试断路器
            TimeUnit.MILLISECONDS.sleep(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("业务处理时间:"+i);
        return "测试断路器!我是服务提供者！";
    }


}
